function quitaRow(row,tab,sel,val)
{
    var table = document.getElementById(tab); 
    var sel = document.getElementById(sel); 
    var val_ = document.createElement("option");
    val_.innerHTML = val ; 
    table.deleteRow(row); 
    sel.appendChild(val_);
}  

function pegaSelect(sel_,val)
{ 
    var val_ = document.createElement("option");
    val_.innerHTML = val ; 
    sel_.appendChild(val_);
}

function rmv(i,s,v)
{  
  
    $(i).parent().parent().remove();  
    pegaSelect(s,v); 
}

var c = "'";

function rp(str)
{  
    var n = "";
    for (var i = 0; i < str.length; i++)
    {
        if(str[i] == "\\")
            n+"\\\\";
        else
            n+str[i]; 
        console.log(n);
    } 
    return n;
}

function addNuevaRow(target,opt)
{      
    var t_= ""; 
    var val = getSelectedText(target);  
    if(val != null)
    {   
        if(target == "sel_tbsp")
            t_ = "tabla_tbsp"; 
        else if(target == "sel_init")
            t_ = "tabla_init";
        else if (target == "sel_control")
            t_ = "tabla_control"; 
        else if(target == "sel_arc")
            t_ = "tabla_arc";
        else if (target == "sel_log")
            t_ = "tabla_log";
        var table = document.getElementById(t_); 
        var t_size = "";  
         var rmval;
        if(t_!= "tabla_tbsp")
            t_size = $('#'+t_+' tr').length;   
        else
        {
            var pars = val.split(","); 
            var par0 = pars[0].split("[");
            var par1 = pars[1].split("]");
            console.log(pars); 
            console.log(par0);
            console.log(par1);  
            t_size = par0[1]; 
            val = par1[0];
            rmval = rp(c+val+c);
        }
        var td2 = '<span>'+val+'</span>&nbsp<span class="glyphicon glyphicon-remove-sign" onclick="rmv(this,'+target+','+rmval+')"></span>';
        var r_ = "<tr><td>"+opt+t_size+"</td><td>"+td2+"</td></tr>";
        $(r_).appendTo($("#"+t_));
        var sel = document.getElementById(target); 
        sel.remove(sel.selectedIndex);
        return true;
    }
    return false;
}
 
 function getSelectedText(elementId) 
 {
    
    var elt = document.getElementById(elementId);
    if(elt != null)
    {
    
        if (elt.selectedIndex == -1 || elt.selectedIndex == 0)
        {
    
            return null;
        }
        return elt.options[elt.selectedIndex].text;
    } 
    return null;
} 

function getDataTable(table,row)
{  
    var arr = new Array();
    var MyRows = $('#'+table).find('tbody').find('tr');
    for (var i = 0; i < MyRows.length; i++) 
    {
         arr.push($(MyRows[i]).find('td:eq('+row+')').find('span').html()); 
    }
    return arr;
}